'''
Author: “cool_at_night” 781458665@qq.com
Date: 2024-10-19 23:54:04
LastEditors: “cool_at_night” 781458665@qq.com
LastEditTime: 2024-11-23 13:17:00
FilePath: \BERT-pytorch-master\random_100.py
Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
'''
import random
def random_select(cnt: int, file_path: str, out_path: str) -> None:
    """
    随机从一个文本中选择cnt行，并将其保存在一个新的文本中。
    """
    new_file=open(out_path,'w',encoding='utf-8')
    with open(file_path, 'r') as f:
        lines = f.readlines()
        random_lines=random.sample(lines,cnt)
        new_file.write(''.join(random_lines))
    new_file.close()
    print(f'成功选取{cnt}条')

if __name__ == '__main__':
    random_select(100, 'data/corpus_large.small', 'data/corpus.small')